package com.example.pufang.controller;

import com.example.common.CommonResult;
import com.example.common.PageParamRequest;
import com.example.pufang.pojo.House;
import com.example.pufang.pojo.User;
import com.example.pufang.service.HouseService;
import com.example.pufang.vo.PageListVo;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/house")
@CrossOrigin
@Api(tags = "web房源接口")
public class HouseController {

    @Autowired
    private HouseService houseService;

    @Operation(summary = "获取分页用户列表")
    @GetMapping("/getListByPage")
    public CommonResult<PageListVo> getListByPage(PageParamRequest pageParamRequest,
                                                  String searchPhone, String searchName, String searchRealName) {
        return CommonResult.success(houseService.getListByPage(pageParamRequest, searchName, searchRealName, searchPhone));
    }

    @Operation(summary = "取消展示/下架")
    @PostMapping("ban")
    public CommonResult<Boolean> ban(@RequestBody House house) {
        Boolean result = houseService.ban(house);
        if (result) {
            return CommonResult.success(true, "下架成功");
        } else {
            return CommonResult.failed("下架失败");
        }
    }

    @Operation(summary = "上架")
    @PostMapping("cancelBan")
    public CommonResult<Boolean> cancelBan(@RequestBody House house) {
        Boolean result = houseService.cancelBan(house);
        if (result) {
            return CommonResult.success(false, "上架成功");
        } else {
            return CommonResult.failed("上架失败");
        }
    }

}
